package com.itheima.server.controller;

import com.itheima.server.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author 阿鹏
 * @date 2021/2/2 22:01
 */
@RestController
@RequestMapping("messages")
public class MessageController {

    @Autowired
    private MessageService messageService;

    @PostMapping("/contacts")
    public ResponseEntity contactWithStranger(@RequestBody Map map) {
        Long userId = Long.valueOf(map.get("userId").toString());
        return messageService.contactWithStranger(userId);
    }

    @GetMapping("/contacts")
    public ResponseEntity findFriend(@RequestParam(defaultValue = "1") int page,
                                     @RequestParam(defaultValue = "10") int pagesize,
                                     @RequestParam(required = false) String keyword) {
        return messageService.findFriend(page, pagesize, keyword);
    }

    /**
     * CommentType 点赞是1 评论是2  喜欢是3
     */
    @GetMapping("likes")
    public ResponseEntity findLikePerson(@RequestParam(defaultValue = "1") int page,
                                         @RequestParam(defaultValue = "10") int pagesize){
        return messageService.findLikePerson(1,page, pagesize);
    }

    @GetMapping("comments")
    public ResponseEntity findCommentsPerson(@RequestParam(defaultValue = "1") int page,
                                             @RequestParam(defaultValue = "10") int pagesize) {
        return messageService.findLikePerson(2,page, pagesize);
    }

    @GetMapping("loves")
    public ResponseEntity findLovesPerson(@RequestParam(defaultValue = "1") int page,
                                          @RequestParam(defaultValue = "10") int pagesize) {
        return messageService.findLikePerson(3,page, pagesize);
    }

    @GetMapping("/announcements")
    public ResponseEntity findAnnouncements(@RequestParam(defaultValue = "1") int page,
                                            @RequestParam(defaultValue = "10") int pagesize) {
        return messageService.findAnnouncements(page, pagesize);
    }
}
